import re

######################### DICTONARY ################################

title_names = ['title','name','recipe name']
category_names = ['category','categorie','genre','group','sort','type','variety','kind']
ingredients_names = ['ingredient','element','pieces']

for name in title_names[:]:
	title_names.append(name + 's')
for name in category_names[:]:
	category_names.append(name + 's')
for name in ingredients_names[:]:
	ingredients_names.append(name + 's')

search_methods = []
search_methods.append(title_names)
search_methods.append(category_names)
search_methods.append(ingredients_names)
search_methods = sum(search_methods, [])

classes = {
"help" : ["help", "lost", "scary", "shit", "fucked up", "confused", "don't understand", "dont understand", "not sure"],
"hello" : ["hi", "hello", "hey", "yo", "salut", "bonjour"],
"modals" : "do will should would can would".split(),
"desire" : "love like need hate dislike".split(),
"action" : "search look try make do".split(),
"be" : "am feel".split(),
"next" : ["next", "proceed", "continue", "go on", "complete", "done", "move on"],
"show" : ["show", "display", "see", "look", "check out", "print"],
"select" : ["select", "choose", "pick", "do", "make", "go with", "go for"],
"suggest" : "suggest".split(),
"simplest" : "simple simplest".split(),
"options" : ["options", "list", "go back", "results"],
"this" : ["this", "that"],
"quit" : "quit exit leave bye goodbye adios".split(),
"number" : "one two three four five six first second third fourth fifth sixth 1 2 3 4 5 6".split(),
"recipe" : ["recipe", "the recipe"],
"ingredients" : ["ingredients", "ingredient"],
"step" : ["step", "direction", "instruction", "each step", "step by step", "step-by-step"],
"steps" : ["walk through", "walk me through", "steps", "directions", "instructions", "procedures"],
"yes" : ["ok", "next", "yes", "yah", "y", "mhmm", "affirmative", "ya", "yea", "go on", "next", "proceed", "continue", "go on", "complete", "done", "move on"],
"next" : ["next", "proceed", "continue", "go on", "complete", "done", "move on"],
"startover" : ["start over", "restart", "try again", "from the beginning", "start again"],
"method" : search_methods,
"title": title_names,
"category" : category_names,
"ingredients" : ingredients_names,
'no' : "n no not don't can't nay negative uh-huh nope".split(),
'back' : "back previous earlier past".split(),
'thank' : "great thanks thank merci gracias danke xie spasibo toda".split(),
'hungry' : 'famished ravenous hungry starving malnourished'.split()
}
#################### REGEXP GENERATION ##############################

#creates a re that matches any of the contents of a list
def createReFromList(words):
	pattern = '([^a-zA-Z]|^)('
	first = True
	for item in words:
		if not first: 
			pattern += '|'
		else: first = False
		pattern += item
	pattern += ')([^a-zA-Z]|$)'
	return re.compile(pattern)

REs = {}

for c in classes:
	REs[c] = createReFromList(classes[c])

########################## FUNCTIONS ###################################

def classify(s,t):
	return  REs[t].search(s)
	
def classifyAll(s):
	ret = []
	for cl in REs:
		if REs[cl].search(s):
			ret.append(cl)
	return ret
		